<?php
use ODP\FileWriter;
include 'FileWriter.php';
/**
 * Created by PhpStorm.
 * User: evenvi
 * Date: 16-9-19
 * Time: 下午5:50
 */

date_default_timezone_set('Asia/Shanghai');

//file_put_contents('/tmp/aaaa', var_export($_SERVER, true));
//file_put_contents('/tmp/aaaa', var_export(getallheaders(), true));

$encoding = isset($_SERVER['HTTP_CONTENT_ENCODING'])?$_SERVER['HTTP_CONTENT_ENCODING']:"";
$row_post_data = file_get_contents("php://input");
//$post_data = $row_post_data;

/**
 * gzcompress => zlib  deflate
 * gzdecode => gzip  gzip
 * gzdeflate => DEFLATE  deflate-raw
 */

//$post_data = gzdecode($row_post_data);
switch($encoding) {
    case 'gzip':
        $post_data = gzdecode($row_post_data);
        break;
    case 'deflate':
//        $post_data = gzinflate(substr($row_post_data, 2, -4)) . PHP_EOL . PHP_EOL;
//        $post_data = gzinflate(substr($row_post_data, 10, -8)) . PHP_EOL . PHP_EOL;
        $post_data = gzuncompress($row_post_data);
        break;
    case 'deflate-raw':
        $post_data = gzinflate($row_post_data);
        break;
    default:
        $post_data = $row_post_data;
        break;
}

$fw = new FileWriter\FileWriter();
$fw->write($post_data);